package compiler;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import language.LType;

public class NamedSupplier extends Named implements Sup {

    NamedSupplier(List list, Map<String, LType> constants) {
        super(list, constants);
    }

    LType call() {
        return new Instance().next();
    }

    @Override
    public LType get(Map<Character, LType> vars) {
        return call();
    }

    class Instance extends Named.Instance {

        @Override
        Object of(String s) {
            if (constants.containsKey(s)) {
                return constants.get(s);
            }
            return null;
        }

        @Override
        Map<Character, LType> newMap() {
            return new HashMap();
        }
    }

    @Override
    public String toString() {
        LType call = call();
        if (call != null) {
            return call.toString();
        }
        return "";
    }
}
